package org.ttitfly.zuoyue.service.complaint;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.ttitfly.zuoyue.dao.complaint.ComplaintDao;
import org.ttitfly.zuoyue.entity.complaint.Complaint;
import org.ttitfly.zuoyue.so.complaint.ComplaintSO;

@Component("complaintManager")
public class ComplaintManager {
	@Resource
	private ComplaintDao complaintDao;

	public ComplaintDao getComplaintDao() {
		return complaintDao;
	}

	public void setComplaintDao(ComplaintDao complaintDao) {
		this.complaintDao = complaintDao;
	}
	
	public int getSOComplaintViewCount(ComplaintSO so) {
        return complaintDao.getSOComplaintViewCount(so);
    }

	public List<Complaint> getSOComplaintView(ComplaintSO so) {
        return complaintDao.getSOComplaintView(so);
    }
	
	/**
	 *根据投诉ID字符串获得投诉对象列表
	 * @param strComplaints 投诉ID字符串
	 * @return
	 */
	public List<Complaint> findComplaints(String strComplaints){
		List<Complaint> complaints = new ArrayList<Complaint>();
		if(StringUtils.isNotBlank(strComplaints)){
			String[] strIds = strComplaints.split(",");
			for(String strId : strIds){
				ComplaintSO so = new ComplaintSO();
				so.setPageSize(5);
				so.setCurrentPage(0);
				so.setId(Long.parseLong(strId));
				List<Complaint> list =complaintDao.getSOComplaintView(so);
				if(list != null && list.size()>0){
					complaints.add(list.get(0));
				}
			}
		}
		
		return complaints;
	}
	

	/**
	 *根据投诉ID字符串的集合查询投诉信息
	 * @param complaintIDs 投诉ID字符串列表
	 * @return List<Complaint>
	 */
	public List<Complaint> findComplaintsByIDs(List<Long> complaintIDs){
		List<Complaint> complaints = new ArrayList<Complaint>();
		if(complaintIDs != null && complaintIDs.size() > 0){
			complaints =complaintDao.getComplaintsByIDs(complaintIDs);
		}
		
		return complaints;
	}

	/**
	 * 根据投诉id信息查询投诉信息
	 * @param id
	 * @return Complaint
	 */
	public Complaint findComplaintById(long id){
		if(id <= 0){
			return null;
		}
		return complaintDao.getComplaintById(id);
	}
}
